package cn.kgc.shiro03.service.impl;

import cn.kgc.shiro03.util.SaltUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.kgc.shiro03.entity.User;
import cn.kgc.shiro03.service.UserService;
import cn.kgc.shiro03.mapper.UserMapper;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>implements UserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public Map<String, Object> register(String username, String password) {

        HashMap<String, Object> map = new HashMap<>();
        String salt = SaltUtil.getSalt(8);
        password = new Md5Hash(password, salt, 1024).toHex();

        User user = new User();
        user.setPassword(password);
        user.setSalt(salt);
        user.setUsername(username);

        userMapper.insert(user);
        map.put("code",200);
        map.put("msg","注册成功");

        return map;
    }
}




